function ajax(obj) {
	obj.type = obj.type.toUpperCase() || 'GET';
	let query = '';
	let post='';
	
	let xhr = new XMLHttpRequest();
	if (obj.query && typeof obj.query === 'object') {
		for (let name in obj.query) {
			query += `${name}=${obj.query[name]}&`;
		}
		query = '?' + query.substring(0, query.length - 1);
	}
	
	if (obj.post && typeof obj.post === 'object') {
		for (let name in obj.post) {
			post += `${name}=${obj.post[name]}&`;
		}
		post = post.substring(0, post.length - 1);
	}
	xhr.open(obj.type, obj.url+query);

	if (obj.type === 'GET') {
		xhr.send();
	} else {
		xhr.send(post);
	}

	xhr.onreadystatechange = function() {
		if (xhr.readyState === 4) {
			if (xhr.status === 200 || xhr.status === 304) {
				obj.success(xhr.responseText);
			} else {
				obj.error('no data');
			}
		}
	};
};


